using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;

namespace IQIGame.Onigao.GamePlay
{
    public class UIN_MainFormationHeroHead : UIBaseNode
    {
        #region Template Generate,don't modify
        protected class UIB_UIN_MainFormationHeroHead
        {
            #region ObjectBinding Generate
            public IQIGame.Onigao.Framework.ExImage headIcon { protected set; get; }
            public UnityEngine.GameObject captain { protected set; get; }
            public virtual void InitBinding(ObjectBinding __binding)
            {
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExImage>("headIcon", out var __tbv0);
                this.headIcon = __tbv0;
                __binding.TryGetVariableValue<UnityEngine.GameObject>("captain", out var __tbv1);
                this.captain = __tbv1;
            }
            #endregion ObjectBinding Generate 
        }
        #endregion Template Generate,don't modify

        #region fields



        #endregion fields

        #region properties

        protected UIB_UIN_MainFormationHeroHead ui { get; set; }
        protected UIMsgDispatcher uiMsgDispatcher => this._msgDispatcher as UIMsgDispatcher;

        #endregion properties

        protected override void BeforeInit()
        {
            ui = new UIB_UIN_MainFormationHeroHead();
            ui.InitBinding(this.csObjBind);
        }

        protected override void OnInit()
        {
            var btn = this.gameObject.GetOrAdd<ExButton>();
            btn.onClick.AddListener(OnClickSelf);
        }

        private void OnClickSelf()
        {
            if (FunctionModule.CheckIsOpenAndTip(FunctionType.Formation))
                OpenUI<UIFormation>();
        }

        protected override void OnShow()
        {

        }

        protected override void OnHide()
        {

        }

        /// <summary>
        /// 添加UGUI侦听
        /// </summary>
        protected override void AddUGUIListener()
        {

        }

        /// <summary>
        /// 添加全局侦听（MsgDispatcher）
        /// </summary>
        protected override void AddMsgListeners()
        {

        }

        protected override void OnDispose()
        {

        }

        #region methonds

        public void Show(FormationHeroData formationHeroData)
        {
            this.Show();
            this.SetImageSprite(this.ui.headIcon, formationHeroData.heroData.cfgSkin.HeroHeadImage_fullPath);
            this.ui.captain.SetActive(formationHeroData.isCaptain);
        }

        #endregion methonds
    }
}
